#include <stdio.h>
#include <stdlib.h>

typedef struct nod {
		int value;
		struct nod *next;
} node;

node * add(node * head, int value)
{
	node *temp, *dummy;

	dummy = malloc(sizeof(node()));
	dummy->value = value;
	dummy->next = NULL;

	if(head) {
		temp = head;
		while(temp->next)
			temp = temp->next;
		temp->next = dummy;
	} else
		head = dummy;

	return head;
}


void list_print(node *temp)
{
	while(temp) {
		printf("%d->", temp->value);
		temp = temp->next;
	}

	printf("<EOL>\n");
}

node * reverse(node *head)
{
	node *active, *child, *parent = NULL;

	active = head;

	if(active) {
		child = active->next;
		while(child) {
			active->next = parent;
			parent = active;
			active = child;
			child = active->next;
		}
		active->next = parent;

		list_print(active);
	}

	return active;

}
	

int main()
{
	node * head = NULL;

	head = add(head, 1);
	head = add(head, 2);
	head = add(head, 3);
	head = add(head, 4);

	list_print(head);
	head = reverse(head);

	return 0;
}
